package com.hsd.util;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

@Component
@Aspect
public class LogUtil {

    @Pointcut("execution(* com.hsd.service.*.*(..))")
    public void xx(){}

    @Before("xx()")
    public void doLog(JoinPoint jp){
        //获取拦截到的连接点的方法名
        Signature signature = jp.getSignature();
        String methodName = signature.getName();
        System.out.println("拦截到的连接点的方法名为:"+methodName);
        String msg =null;
        switch (methodName){
            case "save":
                msg="进行了存钱的操作";
                break;
            case "take":
                msg="进行了取钱的操作";
                break;
            case "transfer":
                msg="进行了转账的操作";
                break;
        }
        //获取拦截到的连接点的方法的参数值
        Object[] args = jp.getArgs();
        msg+="参数：";
        for (int i=0;i<args.length;i++) {
            msg+="第"+(i+1)+"个参数为："+args[i]+"; ";
        }
        System.out.println(msg);
    }
}
